package com.example.wechattakeaway.service.Impl;

import com.example.wechattakeaway.enums.ResultEnum;
import com.example.wechattakeaway.mapper.UserRoleMapper;
import com.example.wechattakeaway.service.RoleService;
import com.example.wechattakeaway.utils.ResultVOUtil;
import com.example.wechattakeaway.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Service
@Repository
public class RoleServiceImpl implements RoleService {

    @Autowired
    UserRoleMapper userRoleMapper;

    @Override
    public ResultVO InsertRole(String roleName) {
        try{
            userRoleMapper.InsertRole(roleName);
        }catch (Exception e){
            e.printStackTrace();
            return ResultVOUtil.error(ResultEnum.NORMAL_ERROR);
        }
        return ResultVOUtil.success();
    }

    @Override
    public ResultVO DeleteRole(Integer roleId) {
        try {
            userRoleMapper.DeleteRole(roleId);
        }catch (Exception e){
            e.printStackTrace();
            return ResultVOUtil.error(ResultEnum.NORMAL_ERROR);
        }
        return ResultVOUtil.success();
    }

    @Override
    public ResultVO SelectRoleById(Integer roleId) {
        String roleName;
        try{
            roleName = userRoleMapper.SelectRoleById(roleId);
        }catch (Exception e){
            e.printStackTrace();
            return ResultVOUtil.error(ResultEnum.NORMAL_ERROR);
        }
        return ResultVOUtil.success(roleName);
    }
}
